package com.lp.easymethodlink.ui;

import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.lp.easymethodlink.model.CallHierarchyNode;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 * 调用链路树单元格渲染器
 */
public class CallHierarchyTreeCellRenderer extends ColoredTreeCellRenderer {
    
    @Override
    public void customizeCellRenderer(@NotNull JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
        if (value instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
            Object userObject = treeNode.getUserObject();
            
            if (userObject instanceof CallHierarchyNode) {
                CallHierarchyNode node = (CallHierarchyNode) userObject;
                
                // 显示类名和方法名
                append(node.getClassName() + "." + node.getMethodName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
                
                // 如果是Controller方法，显示API路径
                if (node.isControllerMethod()) {
                    append(" [" + node.getHttpMethod() + " " + node.getApiPath() + "]", 
                           SimpleTextAttributes.GRAYED_ATTRIBUTES);
                }
            }
        }
    }
}